using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class JobSeekers_jobalert : System.Web.UI.Page
{
    string connectionString = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        connectionString =
         WebConfigurationManager.ConnectionStrings[
           "RecruitVietnam"].ConnectionString;
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            string jobAlertID = 
            Request.QueryString.Get("JobAlertID");
            DropDownListHelper helper 
            = new DropDownListHelper();
            Common cls = new Common(connectionString);
            DataSet dataSet = cls.GetDataSet(
            "select * from tblJobCategories; " +
            "Select * from tblJobIndustries;");
            DropDownList[] dropDownLists = new 
            DropDownList[2] { ddlJobCategory, 
            ddlJobIndustry};
            helper.FillDataTableToDropDownList(
            dataSet, dropDownLists,
            new string[2] { "JobCategoryName", 
            "JobIndustryName"},
            new string[2] { "JobCategoryID", 
            "JobIndustryID" },
            new string[2] { "", "" });
            if (!IsPostBack)
                EditJobAlert(jobAlertID);
            
        }
    }
     
    void EditJobAlert(string jobAlertID)
    {
        if (jobAlertID != "" && jobAlertID != null)
        {
            SqlServerProvider cls = new SqlServerProvider(connectionString);
            cls.CommandText = "select * from tblJSJobAlerts" +
            " where UserID=@UserID and  AlertID= @AlertID ";
            cls.ParameterCollection = new string[2] { "@UserID", "@AlertID" };
            cls.ValueCollection = new string[2] { Session["jsuserid"].ToString(), jobAlertID };
            DataRow dataRow =
            cls.GetDataRow();
            if (dataRow != null)
            {
                AlertID.Value = dataRow[0].ToString();
                txtKeyword.Text = dataRow[2].ToString();
                txtCity.Text = dataRow[3].ToString();
                ddlJobCategory.SelectedValue = dataRow[4].ToString();                 
                ddlJobIndustry.SelectedValue = dataRow[5].ToString();
                txtEmail.Text = dataRow[6].ToString();
                ddlSchedule.SelectedValue = dataRow[7].ToString(); 
                            
            }
        }
        else
            txtEmail.Text = Session["jsemail"].ToString();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        RecruitVietnam cls = new RecruitVietnam();
        cls.ConnectionString = connectionString;
        if (!cls.SaveAlert((AlertID.Value != ""?AlertID.Value:"0"), 
        Session["jsuserid"].ToString(),
        txtKeyword.Text,
        txtCity.Text, 
        ddlJobCategory.SelectedValue,
        ddlJobIndustry.SelectedValue,
        txtEmail.Text, ddlSchedule.SelectedValue))
            literalError.Text = cls.ErrorMessage;
        else
            Response.Redirect("jobalerts.aspx");
    }
}
